home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ClockPrt.cpp
-
- Contains: ClockPart C++ helper object
-
- Owned by: Richard Rodseth
-
- Copyright: © 1995 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <3> 10/15/96 JP 1375124 : Used Active Part prop when
- recording.
- <2> 7/16/96 EL 1295068: Do not externalize unless it is
- dirty.
- <28> 10/23/95 RR #1291688 Added test for adding New menus
- <27> 10/18/95 RR 1289153: Recover from exceptions creating
- windows. Store fPlatformWindow pointer in
- ClockFrame, so we can get to it even if
- odWindow isn't successfully created.
- Release remaining frames in ReleaseAll().
- <26> 10/17/95 jpa Recover from exceptions thrown by
- RegisterWindowForFrame [1289153]
- <25> 10/16/95 RR #1293067 Pass shouldDispose to
- RegisterWindow
- <24> 25/09/95 NP 1979071: Check results of operator new.
- <23> 9/21/95 RR Allocate synch dialog out of temp mem
- <22> 9/12/95 RR Various activation problems. Added a
- floating window
- <21> 9/12/95 JP 1280292 & 1283803: Add Part to Send
- <20> 9/11/95 NP 1272294: Messaging code cleanup.
- <19> 9/1/95 RR # 1244639 Delete window record when frame
- is closed/removed
- <18> 8/25/95 JP 1268279: Send part to frame fallout
- <17> 8/15/95 RR HandleOSEvent improvements
- <16> 8/8/95 jpa Removed DebugStrs [1265584]
- <15> 7/10/95 RR Misc. cleanup and bug fixes for shared
- window
- <14> 7/10/95 JP Scripting cleanup
- <13> 7/7/95 RR Some refactoring. Fix
- CreatePropObjSpecifier to deal with
- non-persistent frame. Set source frame of
- dialogs.
- <12> 7/3/95 RR Added #if ODDebug around DebugStr
- <11> 6/30/95 RR 1242642 BB Ref counting fixes. Display
- settings window is saved as an ID, not a
- window
- <10> 6/29/95 VL 1242642: Release the created su in
- CloneInto.
- <9> 6/25/95 TÇ 1242642 BB: Turn on ODDebug warning if
- refcount is wrong in
- ODRefCntObjectsomUninit.
- <8> 6/22/95 jpa (oops, removed bogus in progress comment.)
- <7> 6/22/95 jpa Fixed refcounting of semantic interface.
- [1261644]
- <6> 6/20/95 JP 1251250: Acquire & Release extension
- properly
- <5> 6/13/95 JP Recordable Clock
- <4> 6/8/95 jpa Use temp objects (TempODShape,
- TempODFrame). [1246062]
- <3> 6/8/95 RR #1257260 Collapse base classes. #1214898
- StdTypes.r -> ODTypes.r
- <2> 6/3/95 TJ Added #includes for compile with out PCH
- <1> 5/31/95 RR first checked in
-
- To Do:
- In Progress:
-
- */
-
- #ifndef _ALTPOINT_
- #include "AltPoint.h" // Use C++ savvy ODPoint and ODRect
- #endif
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_ODRefCntObject_xh
- #include "RefCtObj.xh"
- #endif
-
- #ifndef SOM_ODPart_xh
- #include "Part.xh"
- #endif
-
- #ifndef _CLOCKFRM_
- #include "ClockFrm.h"
- #endif
-
- #ifndef _CLOCKGBL_
- #include "ClockGbl.h"
- #endif
-
- #ifndef _CLOCKPRT_
- #include "ClockPrt.h"
- #endif
-
- #ifndef _CLOCKDEF_
- #include "ClockDef.h"
- #endif
-
- #ifndef _PLFMDEF_
- #include "PlfmDef.h"
- #endif
-
-
- #ifndef _SIHELPER_
- #include "SIHelper.h"
- #endif
-
- #ifndef SOM_Module_OpenDoc_Foci_defined
- #include <Foci.xh>
- #endif
-
- #ifndef _USERSRCM_
- #include "UseRsrcM.h"
- #endif
-
- #ifndef SOM_ODFocusSet_xh
- #include <FocusSet.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
-
- #ifndef SOM_Module_OpenDoc_StdDefs_defined
- #include <StdDefs.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitCursor_xh
- #include <SUCursor.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include <FrFaItr.xh>
- #endif
-
- #ifndef _ORDCOLL_
- #include "OrdColl.h"
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef SOM_ODMenuBar_xh
- #include <MenuBar.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef _ITEXT_
- #include <IText.h>
- #endif
-
- #ifndef _ISOSTRING_
- #include "ISOStr.h"
- #endif
-
- #ifndef SOM_ODMessageInterface_xh
- #include <MssgIntf.xh>
- #endif
-
- #ifndef _AEOBJECTS_
- #include "AEObjects.h"
- #endif
-
- #ifndef _FOCUSLIB_
- #include "FocusLib.h"
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __OSUTILS__
- #include <OSUtils.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __DIALOGS__
- #include "Dialogs.h"
- #endif
-
- #ifndef __TEXTEDIT__
- #include <TextEdit.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __STRINGS__
- #include <Strings.h>
- #endif
-
- #ifndef __FP__
- #include <Fp.h>
- #endif
-
- #include <string.h>
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _STDTYPIO_
- #include "StdTypIO.h"
- #endif
-
- #ifndef _INFOUTIL_
- #include <InfoUtil.h>
- #endif
-
- #ifndef _WINUTILS_
- #include "WinUtils.h"
- #endif
-
- #ifndef _ITEXT_
- #include <IText.h>
- #endif
-
- #ifndef _PASCLSTR_
- #include "PasclStr.h"
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _POUTILS_
- #include <POUtils.h> // for UpdateModificationInfo
- #endif
-
- #ifndef _CLOCKOBJ_
- #include "ClockObj.h"
- #endif
-
- #ifndef SOM_ClockSI_xh
- #include "ClockSI.xh"
- #endif
-
- #ifndef __AEPACKOBJECT__
- #include <AEPackObject.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_ODRegistry_defined
- #include "ODRgstry.xh"
- #endif
-
- #ifndef __ASREGISTRY__
- #include <ASRegistry.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef _SEUTILS_
- #include "SEUtils.h"
- #endif
-
- #ifndef _ODDESUTL_
- #include <ODDesUtl.h>
- #endif
-
- #ifndef SOM_ODAddressDesc_xh
- #include "ODAdrDes.xh"
- #endif
-
- #ifndef SOM_ODAppleEvent_xh
- #include <ODAplEvt.xh>
- #endif
-
- #define ODDebugLayers 0
-
- //=========================================================================
- // Local Functions
- //=========================================================================
-
- static ODFrame* AquirePersistantFrame(Environment* ev, ODFrame* frame);
-
- //=========================================================================
- // ClockPart
- //=========================================================================
-
- ClockPart::ClockPart()
- {
- fContentFrames = kODNULL; // Create an empty collection for storing the list
- // of frames to display the "clock" in.
-
- fFont = GetSysFont(); // Script Mgr: get the current system font
- fSize = GetDefFontSize(); // Script Mgr: get the current default font size
- fStyle = normal; // Font Mgr: enum for plain style
-
- fLastAscent = 0; // Ascent of the fFont font - used in positioning for drawing
-
- fFontMenu = kODNULL;
- fSizeMenu = kODNULL;
- fStyleMenu = kODNULL;
- fViewMenu = kODNULL;
- fExtraMenu = kODNULL;
- fExtraSubMenu = kODNULL;
- fMenuBar = kODNULL;
- fSemanticInterface = kODNULL;
- fTestClockSU = kODNULL;
- fWorkPort = kODNULL;
-
- fAlarmEnabled = kODFalse;
- fAnalog = kODFalse;
-
- fPartWrapper = kODNULL;
- fSOMSelf = kODNULL;
-
- fModalFocus = kODNULL;
- fFrameView = kODNULL;
- fTimePresentation = kODNULL;
- fSynchronizePresentation = kODNULL;
-
- fDirty = kODFalse;
- }
-
- ClockPart::~ClockPart()
- {
- Environment* ev = somGetGlobalEnvironment();
-
- ODDeleteObject(fContentFrames);// Release the display frames collection.
- // Deletion of memory used by the object will be
- // reclaimed when the shell deletes the
- // instantiation.
- if (fWorkPort)
- DisposeWindow(fWorkPort);
- //ODDisposePtr(fWorkPort);
-
- delete fSemanticInterface; // Refcount must be zero by now.
- }
-
- void ClockPart::InitClockPart(Environment* ev,
- ODSession* session,
- ODPart* somSelf,
- ODPart* partWrapper)
- {
- if (gClockGlobals)
- gClockGlobals->AcquireGlobals(ev);
- else
- {
- gClockGlobals = new ClockGlobals();
- gClockGlobals->InitClockGlobals(ev, session, partWrapper);
- gClockGlobals->AcquireGlobals(ev);
- }
-
- fSOMSelf = somSelf;
- fPartWrapper = partWrapper;
-
- fSession = session; //$$$$$ fSOMSelf->GetStorageUnit(ev)->GetSession(ev);
-
- fArbitrator = fSession->GetArbitrator(ev);
- fDispatcher = fSession->GetDispatcher(ev);
- fWindowState = fSession->GetWindowState(ev);
-
- fSemanticInterface = new ClockSI;
- SIHelper* semItfcHelper = new SIHelper;
- semItfcHelper->InitSIHelper(fSession, fSemanticInterface);
- fSemanticInterface->InitCPlusSemanticInterface(ev, somSelf, semItfcHelper, fSession);
- InstallStaticCallbacks(semItfcHelper, this);
-
- Rect r;
- SetRect(&r, 0,0,0,0);
-
- fWorkPort = NewCWindow(NULL, &r, "\p", kODFalse, documentProc, NULL, kODFalse, 0);
- //fWorkPort = NewCWindow((Ptr)ODNewPtr(sizeof(WindowRecord)), &r, "\p", kODFalse, documentProc, NULL, kODFalse, 0);
-
- fModalFocus = fSession->Tokenize(ev, kODModalFocus);
- fFrameView = fSession->Tokenize(ev, kODViewAsFrame);
- fTimePresentation = fSession->Tokenize(ev, kClockFrame);
- fSynchronizePresentation = fSession->Tokenize(ev, kSynchronizeFrame);
- fAlarmSettingsPresentation = fSession->Tokenize(ev, kAlarmSettingsFrame);
- fDisplaySettingsPresentation = fSession->Tokenize(ev, kDisplaySettingsFrame);
- fDialogPresentation = fSession->Tokenize(ev, kDialogFrame);
-
- fContentFrames = new OrderedCollection; // Create an empty collection for storing the list
- // of frames to display the "clock" in.
-
- ODSLong savedRefNum;
- BeginUsingLibraryResources(savedRefNum);
-
- fFontMenu = NewMenu(kClock_FontMenuID,"\pFont");
- fSizeMenu = NewMenu(kClock_SizeMenuID,"\pSize");
- fStyleMenu = GetMenu(kClock_StyleMenuID);
- DetachResource((Handle) fStyleMenu);
- fSettingsMenu = GetMenu(kClock_SettingsMenuID);
- DetachResource((Handle) fSettingsMenu);
- fViewMenu = GetMenu(kClock_ViewMenuID);
- DetachResource((Handle) fViewMenu);
- #if ODDebug
- if (!fFontMenu || !fSizeMenu || !fStyleMenu || !fSettingsMenu || !fViewMenu)
- WARN("Error creating menus");
- #endif
- AppendResMenu( fFontMenu, 'FOND' );
-
- AppendMenu(fSizeMenu,"\p9"); // • • Move to resources for localization
- AppendMenu(fSizeMenu,"\p10");
- AppendMenu(fSizeMenu,"\p11");
- AppendMenu(fSizeMenu,"\p12");
- AppendMenu(fSizeMenu,"\p14");
- AppendMenu(fSizeMenu,"\p18");
- AppendMenu(fSizeMenu,"\p24");
- AppendMenu(fSizeMenu,"\p36");
-
- EndUsingLibraryResources(savedRefNum);
- this->BuildMenuBar(ev);
-
- }
-
- void ClockPart::PrepareStorage(Environment* ev, ODStorageUnit* storageUnit)
- {
- storageUnit->AddProperty(ev, kODPropContents)->AddValue(ev, kODKindTestClock);
-
- fTestClockSU = storageUnit->GetDraft(ev)->CreateStorageUnit(ev);
-
- fTestClockSU->AddProperty(ev,kPropClockType)->AddValue(ev, kODBoolean);
- fTestClockSU->AddProperty(ev,kPropClockFont)->AddValue(ev, kODUShort);
- fTestClockSU->AddProperty(ev,kPropClockStyle)->AddValue(ev, kODUShort);
- fTestClockSU->AddProperty(ev,kPropClockSize)->AddValue(ev, kODUShort);
- fTestClockSU->AddProperty(ev,kODPropDisplayFrames)->AddValue(ev, kODWeakStorageUnitRefs);
- fDirty = kODTrue;
- }
-
- void ClockPart::Release(Environment* ev)
- {
- // SOM method has already called parent_Release()
-
- if ( fSOMSelf->GetRefCount(ev) == 0 )
- fSOMSelf->GetStorageUnit(ev)->GetDraft(ev)->ReleasePart(ev, fPartWrapper);
- }
-
- void ClockPart::ReleaseAll(Environment* ev)
- {
- ODFinalReleaseObject(ev,fSemanticInterface);
- ODReleaseObject(ev,fMenuBar);
- ODReleaseObject(ev,fTestClockSU);
-
- if (gClockGlobals)
- gClockGlobals->ReleaseGlobals(ev);
-
- OrderedCollectionIterator iter(fContentFrames);
-
- for (ODFrame* aFrame = (ODFrame*)iter.First();
- iter.IsNotComplete();
- aFrame = (ODFrame*)iter.Next())
- {
- ODReleaseObject(ev, aFrame);
- }
- }
-
- void ClockPart::Internalize(Environment* ev, ODStorageUnit* storageUnit)
- {
- ODULong valueSize, offset;
- ODStorageUnitRef aSURef;
- ODFrame* aFrame;
- ODStorageUnit* su;
-
- su = storageUnit; //$$$$$ somSelf->GetStorageUnit(ev);
- su->Focus(ev, kODPropContents,kODPosSame,kODKindTestClock,1,kODPosFirstSib);
- StorageUnitGetValue(su, ev, sizeof(ODStorageUnitRef),&aSURef);
- if (su->IsValidStorageUnitRef(ev, aSURef))
- fTestClockSU = su->GetDraft(ev)->AcquireStorageUnit(ev, su->GetIDFromStorageUnitRef(ev, aSURef));
- else
- WARN("No Clock SU");
- su = fTestClockSU;
-
- su->Focus(ev, kPropClockType,kODPosSame,kODBoolean,1,kODPosFirstSib);
- StorageUnitGetValue(su, ev, sizeof(ODBoolean), (ODValue)&fAnalog);
- su->Focus(ev, kPropClockFont,kODPosSame,kODUShort,1,kODPosFirstSib);
- StorageUnitGetValue(su, ev, sizeof(ODSShort), (ODValue)&fFont);
- su->Focus(ev, kPropClockStyle,kODPosSame,kODUShort,1,kODPosFirstSib);
- StorageUnitGetValue(su, ev, sizeof(ODSShort), (ODValue)&fStyle);
- su->Focus(ev, kPropClockSize,kODPosSame,kODUShort,1,kODPosFirstSib);
- StorageUnitGetValue(su, ev, sizeof(ODSShort), (ODValue)&fSize);
-
- //$$$$$ CloneInto does not currently externalize display frames
- if ( su->Exists(ev,kODPropDisplayFrames, kODNULL, 0) )
- {
- su->Focus(ev, kODPropDisplayFrames,kODPosUndefined,0,1,kODPosFirstSib);
- valueSize = su->GetSize(ev);
- for (offset = 0; offset < valueSize; offset += sizeof(ODStorageUnitRef))
- {
- su->SetOffset(ev, offset);
- StorageUnitGetValue(su, ev, sizeof(ODStorageUnitRef), (ODValue)&aSURef);
-
- if (su->IsValidStorageUnitRef(ev, aSURef)) {
- aFrame = su->GetDraft(ev)->AcquireFrame(ev, su->GetIDFromStorageUnitRef(ev, aSURef));
- this->AddContentFrame(ev, aFrame);
- aFrame->Release(ev); // Because both AddContentFrame and GetFrame increment
- }
- else
- aFrame = kODNULL;
- }
- }
- fDirty = kODFalse;
- // We should minimize the frame shape here, but we can't because I think that
- // the _fClockPart->fPart and _fClockPart->fPartInfo for the frame hasn't been set up yet.
- // somSelf->AdjustFrameShape(ev, dispFrame);
- }
-
-
- ODInfoType ClockPart::ReadPartInfo(Environment *ev,
- ODFrame* frame,
- ODStorageUnitView* storageUnitView)
- {
- if (storageUnitView->GetSize(ev))
- {
- ClockTimeFrame* partInfo = new ClockTimeFrame();
- partInfo->InitClockTimeFrame(ev, fSession, frame, this);
-
- /*
- ODBoolean needsActivating;
- StorageUnitGetValue(storageUnitView, ev, sizeof(ODBoolean),
- (ODValue)&(needsActivating));
- partInfo->fNeedsFoci = needsActivating;
- */
- return (ODInfoType)partInfo;
- }
- else
- return ((ODInfoType)kODNULL);
- }
-
- void ClockPart::Externalize(Environment *ev)
- {
- ODFrame* aFrame;
- ODStorageUnitRef aSURef;
- ODULong offset, offsetLimit;
- ODStorageUnit* su = fTestClockSU;
-
- if (fDirty)
- {
- su->Focus(ev, kPropClockType,kODPosSame,kODBoolean,1,kODPosFirstSib);
- StorageUnitSetValue(su, ev, sizeof(ODBoolean), (ODValue)&fAnalog);
- su->Focus(ev, kPropClockFont,kODPosSame,kODUShort,1,kODPosFirstSib);
- StorageUnitSetValue(su, ev, sizeof(ODSShort), (ODValue)&fFont);
- su->Focus(ev, kPropClockStyle,kODPosSame,kODUShort,1,kODPosFirstSib);
- StorageUnitSetValue(su, ev, sizeof(ODSShort), (ODValue)&fStyle);
- su->Focus(ev, kPropClockSize,kODPosSame,kODUShort,1,kODPosFirstSib);
- StorageUnitSetValue(su, ev, sizeof(ODSShort), (ODValue)&fSize);
-
- OrderedCollectionIterator aIter(fContentFrames);
- ODSUForceFocus(ev, su, kODPropDisplayFrames, kODWeakStorageUnitRefs);
- //su->Focus(ev, kODPropDisplayFrames,kODPosUndefined,0,1,kODPosFirstSib);
- offsetLimit = su->GetSize(ev);
- offset = 0;
- for (aFrame = (ODFrame*)aIter.First(); aIter.IsNotComplete();
- aFrame = (ODFrame*)aIter.Next(),
- offset+=sizeof(ODStorageUnitRef))
- {
- su->GetWeakStorageUnitRef(ev, aFrame->GetStorageUnit(ev)->GetID(ev), aSURef);
- su->SetOffset(ev, offset);
- StorageUnitSetValue(su, ev, sizeof(ODStorageUnitRef), aSURef);
- }
- if (offset < offsetLimit)
- su->DeleteValue(ev, offsetLimit - offset);
-
- su = fSOMSelf->GetStorageUnit(ev);
- su->Focus(ev, kODPropContents,kODPosSame,kODKindTestClock,1,kODPosFirstSib);
- su->GetStrongStorageUnitRef(ev, fTestClockSU->GetID(ev), aSURef);
- StorageUnitSetValue(su, ev, sizeof(ODStorageUnitRef),aSURef);
- fDirty = kODFalse;
- }
- }
-
- void ClockPart::CloneInto(Environment *ev,
- ODDraftKey key,
- ODStorageUnit* storageUnit,
- ODFrame* scopeFrame)
- {
- ODStorageUnitRef aSURef;
-
- ODStorageUnit* su = storageUnit->GetDraft(ev)->CreateStorageUnit(ev);
-
- //$$$$$$ ODSUForceFocus is not a public utility
-
- ODSUForceFocus(ev, su, kPropClockType, kODBoolean);
- StorageUnitSetValue(su, ev, sizeof(ODBoolean), (ODValue)&fAnalog);
- ODSUForceFocus(ev, su, kPropClockFont, kODUShort);
- StorageUnitSetValue(su, ev, sizeof(ODSShort), (ODValue)&fFont);
- ODSUForceFocus(ev, su, kPropClockStyle, kODUShort);
- StorageUnitSetValue(su, ev, sizeof(ODSShort), (ODValue)&fStyle);
- ODSUForceFocus(ev, su, kPropClockSize, kODUShort);
- StorageUnitSetValue(su, ev, sizeof(ODSShort), (ODValue)&fSize);
-
- //$$$$$ Display Frames?
- /*OrderedCollectionIterator aIter(fContentFrames);
- su->Focus(ev, kODPropDisplayFrames,kODPosUndefined,0,1,kODPosFirstSib);
- offsetLimit = su->GetSize(ev);
- offset = 0;
- for (aFrame = (ODFrame*)aIter.First(); aIter.IsNotComplete();
- aFrame = (ODFrame*)aIter.Next(),
- offset+=sizeof(ODStorageUnitRef))
- {
- su->GetWeakStorageUnitRef(ev, aFrame->GetStorageUnit(ev)->GetID(ev), aSURef);
- su->SetOffset(ev, offset);
- StorageUnitSetValue(su, ev, sizeof(ODStorageUnitRef), aSURef);
- }
- if (offset < offsetLimit)
- su->DeleteValue(ev, offsetLimit - offset);
- */
-
- ODSUForceFocus(ev, storageUnit, kODPropContents, kODKindTestClock);
- storageUnit->GetStrongStorageUnitRef(ev, su->GetID(ev), aSURef);
- StorageUnitSetValue(storageUnit, ev, sizeof(ODStorageUnitRef),aSURef);
- ODReleaseObject(ev, su);
- }
-
- ODTypeToken ClockPart::CheckPresentation(Environment* ev, ODFrame* frame)
- {
- ODTypeToken presentation = frame->GetPresentation(ev);
- if ((presentation != fTimePresentation)
- && (presentation != fSynchronizePresentation)
- && (presentation != fAlarmSettingsPresentation)
- && (presentation != fDisplaySettingsPresentation)
- && (presentation != fDialogPresentation))
- {
- presentation = fTimePresentation;
- frame->SetPresentation(ev, presentation);
- }
- return presentation;
- }
-
- ClockFrame* ClockPart::CreateClockFrame(Environment* ev, ODFrame* frame, ODTypeToken presentation)
- {
- ClockFrame* clockFrame = kODNULL;
- if (presentation == fTimePresentation)
- {
- ClockTimeFrame* timeFrame = new ClockTimeFrame();
- timeFrame->InitClockTimeFrame(ev, fSession, frame, this);
- clockFrame = timeFrame;
- }
- else if (presentation == fSynchronizePresentation)
- {
- ClockSynchroDialogFrame* dialogFrame = new ClockSynchroDialogFrame();
- dialogFrame->InitClockSynchroDialogFrame(ev, fSession, frame, this);
- clockFrame = dialogFrame;
- }
- else if (presentation == fAlarmSettingsPresentation)
- {
- ClockAlarmSettingsDialogFrame* dialogFrame = new ClockAlarmSettingsDialogFrame();
- dialogFrame->InitClockAlarmSettingsDialogFrame(ev, fSession, frame, this);
- clockFrame = dialogFrame;
- }
- else if (presentation == fDisplaySettingsPresentation)
- {
- ClockDisplaySettingsDialogFrame* dialogFrame = new ClockDisplaySettingsDialogFrame();
- dialogFrame->InitClockDisplaySettingsDialogFrame(ev, fSession, frame, this);
- clockFrame = dialogFrame;
- clockFrame->SetShouldDeleteWindow(kODFalse);
- }
- else if (presentation == fDialogPresentation)
- {
- ClockDialogFrame* dialogFrame = new ClockDialogFrame();
- dialogFrame->InitClockDialogFrame(ev, fSession, frame, this);
- clockFrame = dialogFrame;
- clockFrame->SetShouldDeleteWindow(kODFalse);
- }
- return clockFrame;
- }
-
-
- void ClockPart::DisplayFrameAdded(Environment *ev,
- ODFrame* frame)
- {
- // We check for an existing ClockFrame in Part Info, because DisplayFrameAdded
- // can get called multiple times, eg. when changing parts.
- // However DisplayFrameRemoved should probably delete the Part Info
-
- ClockFrame* clockFrame = (ClockFrame*) frame->GetPartInfo(ev);
- if (clockFrame == kODNULL)
- {
- ODTypeToken presentation = this->CheckPresentation(ev, frame);
- clockFrame = this->CreateClockFrame(ev, frame, presentation);
- frame->SetPartInfo(ev, (ODInfoType) clockFrame);
- }
- if (clockFrame)
- {
- clockFrame->SetPart(ev, this);
- clockFrame->Add(ev);
- }
- }
-
- void ClockPart::DisplayFrameConnected(Environment *ev,
- ODFrame* frame)
- {
- ClockFrame* clockFrame = (ClockFrame*) frame->GetPartInfo(ev);
- if (clockFrame == kODNULL)
- {
- ODTypeToken presentation = this->CheckPresentation(ev, frame);
- clockFrame = this->CreateClockFrame(ev, frame, presentation);
- frame->SetPartInfo(ev, (ODInfoType) clockFrame);
- }
- if (clockFrame)
- {
- clockFrame->SetPart(ev, this);
- clockFrame->Connect(ev);
- }
- }
-
- void ClockPart::DisplayFrameRemoved(Environment *ev,
- ODFrame* frame)
- {
- // We don't check _fClockPart->ContainsDisplayFrame because
- // dialog frames are not added to the list
- if ( this->ContainsDisplayFrame(ev, frame))
- {
-
- ClockFrame* clockFrame = (ClockFrame*) frame->GetPartInfo(ev);
- clockFrame->Remove(ev);
- frame->SetPartInfo(ev, (ODInfoType) kODNULL);
- delete clockFrame;
- }
- else
- {
- ClockFrame* clockFrame = (ClockFrame*) frame->GetPartInfo(ev);
- clockFrame->Remove(ev);
- }
-
- }
-
- void ClockPart::DisplayFrameClosed(Environment *ev,
- ODFrame* frame)
- {
- // We don't check _fClockPart->ContainsDisplayFrame because
- // dialog frames are not added to the list
- if ( this->ContainsDisplayFrame(ev, frame))
- {
- ClockFrame* clockFrame = (ClockFrame*) frame->GetPartInfo(ev);
-
- clockFrame->Close(ev);
- frame->SetPartInfo(ev, (ODInfoType) kODNULL);
- delete clockFrame;
-
- }
- else
- {
- ClockFrame* clockFrame = (ClockFrame*) frame->GetPartInfo(ev);
- clockFrame->Close(ev);
- }
- }
-
- ODBoolean ClockPart::ContainsDisplayFrame(Environment* ev, ODFrame* frame)
- {
- if (fContentFrames)
- return fContentFrames->Contains(frame);
- else
- return kODFalse;
- }
-
- void ClockPart::AddContentFrame(Environment* ev, ODFrame* frame)
- {
- if (fContentFrames)
- {
- if (!fContentFrames->Contains(frame))
- {
- fContentFrames->AddLast(frame);
- frame->Acquire(ev);
- }
- }
- }
-
- void ClockPart::RemoveContentFrame(Environment* ev, ODFrame* frame)
- {
- if (fContentFrames && fContentFrames->Contains(frame))
- {
- fContentFrames->Remove(frame);
- ODReleaseObject(ev, frame);
- } else
- WARN("Frame %p is not known to me",frame);
- }
-
-
- void ClockPart::AdjustDisplayFrames(Environment* ev)
- {
- OrderedCollectionIterator iter(fContentFrames);
-
- for (ODFrame* aFrame = (ODFrame*)iter.First();
- iter.IsNotComplete();
- aFrame = (ODFrame*)iter.Next())
- {
- ClockFrame* clockFrame = (ClockFrame*) aFrame->GetPartInfo(ev);
- clockFrame->Adjust(ev);
- }
- }
-
- void ClockPart::AdjustDialogs(Environment* ev)
- {
- gClockGlobals->AdjustDialogs(ev);
- }
-
- void ClockPart::BuildMenuBar(Environment* ev)
- {
- if ((fMenuBar == kODNULL) || !(fMenuBar->IsValid(ev)))
- {
- fMenuBar = fWindowState->CopyBaseMenuBar(ev);
- fMenuBar->AddMenuLast(ev, kClock_FontMenuID, fFontMenu, fPartWrapper);
- fMenuBar->AddMenuLast(ev, kClock_SizeMenuID, fSizeMenu, fPartWrapper);
- fMenuBar->AddMenuLast(ev, kClock_StyleMenuID,fStyleMenu, fPartWrapper);
- fMenuBar->AddMenuLast(ev, kClock_SettingsMenuID, fSettingsMenu, fPartWrapper);
- fMenuBar->AddMenuLast(ev, kClock_ViewMenuID, fViewMenu, fPartWrapper);
-
- fMenuBar->RegisterCommand(ev, cAnalog, kClock_ViewMenuID, 1);
- fMenuBar->RegisterCommand(ev, cDigital, kClock_ViewMenuID, 2);
- fMenuBar->RegisterCommand(ev, cNewView, kClock_ViewMenuID, 4);
- fMenuBar->RegisterCommand(ev, cSynchronize, kClock_SettingsMenuID, 1);
- fMenuBar->RegisterCommand(ev, cShowDisplaySettings, kClock_SettingsMenuID, 2);
- fMenuBar->RegisterCommand(ev, cShowAlarmSettings, kClock_SettingsMenuID, 3);
- fMenuBar->RegisterCommand(ev, cNewFloater, kClock_SettingsMenuID, 4);
- fMenuBar->RegisterCommand(ev, cNewSinker, kClock_SettingsMenuID, 5);
- fMenuBar->RegisterCommand(ev, cNewMenu, kClock_SettingsMenuID, 6);
- }
- }
-
- void ClockPart::InstallMenus(Environment* ev)
- {
- this->BuildMenuBar(ev);
-
- fMenuBar->Display(ev);
-
- this->OutlineSizeMenu(ev);
-
- Str255 tFontName;
-
- GetFontName(fFont, tFontName );
- CheckMarkMenu(fFontMenu, tFontName, kODTrue );
-
- Str255 tSizeStr;
-
- NumToString( (ODULong)fSize, tSizeStr );
- CheckMarkMenu(fSizeMenu, tSizeStr, kODTrue);
-
- Str255 tStyleStr;
-
- StyleToString(fStyle, (Str255 *)&tStyleStr);
- CheckMarkMenu(fStyleMenu, tStyleStr, kODTrue );
- }
-
-
- void ClockPart::OutlineSizeMenu(Environment *ev)
- {
- MenuHandle menu = GetMenuHandle( kClock_SizeMenuID );
-
- // (•) Outline the sizes in the font menu that are available
-
- if (RealFont(fFont, 9))
- SetItemStyle( menu, kClock_Size_9Pt, outline );
- else
- SetItemStyle( menu, kClock_Size_9Pt, normal );
-
- if (RealFont(fFont, 10))
- SetItemStyle( menu, kClock_Size_10Pt, outline );
- else
- SetItemStyle( menu, kClock_Size_10Pt, normal );
-
- if (RealFont(fFont, 11))
- SetItemStyle( menu, kClock_Size_11Pt, outline );
- else
- SetItemStyle( menu, kClock_Size_11Pt, normal );
-
- if (RealFont(fFont, 12))
- SetItemStyle( menu, kClock_Size_12Pt, outline );
- else
- SetItemStyle( menu, kClock_Size_12Pt, normal );
-
- if (RealFont(fFont, 14))
- SetItemStyle( menu, kClock_Size_14Pt, outline );
- else
- SetItemStyle( menu, kClock_Size_14Pt, normal );
-
- if (RealFont(fFont, 18))
- SetItemStyle( menu, kClock_Size_18Pt, outline );
- else
- SetItemStyle( menu, kClock_Size_18Pt, normal );
-
- if (RealFont(fFont, 24))
- SetItemStyle( menu, kClock_Size_24Pt, outline );
- else
- SetItemStyle( menu, kClock_Size_24Pt, normal );
-
- if (RealFont(fFont, 36))
- SetItemStyle( menu, kClock_Size_36Pt, outline );
- else
- SetItemStyle( menu, kClock_Size_36Pt, normal );
- }
-
- void ClockPart::HandleFontMenu(Environment *ev, ODUShort item, ODFrame* frame)
- {
- AEDesc obj, font;
- Str255 fontName;
- ODError err = noErr;
-
- ODPlatformMenu fontMenu = fMenuBar->GetMenu(ev,kClock_FontMenuID);
- GetMenuItemText( fontMenu, item, fontName );
- THROW_IF_ERROR( AECreateDesc(typeChar, &fontName[1], fontName[0], &font) );
- this->CreatePropObjSpec(ev, pFont, obj);
- TRY
- this->SendSetDataEvent(ev, obj, font, frame);
- CATCH_ALL
- err = ErrorCode();
- ENDTRY
- AEDisposeDesc(&font);
- AEDisposeDesc(&obj);
- THROW_IF_ERROR(err);
- }
-
- void ClockPart::ShowAboutBox(Environment* ev, ODFrame* frame)
- {
- TempODFrame currentOwner = fArbitrator->AcquireFocusOwner(ev, fModalFocus);
- if (fArbitrator->RequestFocus(ev, fModalFocus,frame))
- {
- short itemHit;
- ParamText("\pClock Part…",0,0,0);
- SetCursor(&ODQDGlobals.arrow);
- ModalFilterUPP modalFilter = NewModalFilterProc(AboutDialogFilter);
-
- ODSLong savedRefNum;
- BeginUsingLibraryResources(savedRefNum);
- DialogPtr aboutDialog = GetNewDialog(kClock_AboutBoxID ,0,(WindowPtr)-1L);
- EndUsingLibraryResources(savedRefNum);
-
- if (aboutDialog)
- {
- fWindowState->DeactivateFrontWindows(ev); // Can be after GetNewDialog because
- // Dialog is create invisible.
- ShowWindow(aboutDialog);
- do
- {
- ModalDialog(modalFilter, &itemHit);
- } while (itemHit != 1);
- DisposeDialog(aboutDialog);
- fWindowState->ActivateFrontWindows(ev);
- }
- DisposeRoutineDescriptor(modalFilter);
-
- fArbitrator->TransferFocus(ev, fModalFocus,frame, currentOwner);
- }
- else
- SysBeep(2);
- }
-
- void ClockPart::ShowSynchDialog(Environment* ev)
- {
- ODSLong savedRefNum;
- BeginUsingLibraryResources(savedRefNum);
-
- DialogPtr synchDialog = GetNewDialog(kClock_SynchronizeDialogID ,(Ptr)ODNewPtr(sizeof(DialogRecord)),(WindowPtr)-1L);
- EndUsingLibraryResources(savedRefNum);
- ODWindow* synchWindow = fWindowState->
- RegisterWindow(ev, synchDialog,
- kODNonPersistentFrameObject,
- kODFalse, // Keeps draft open
- kODFalse, // Is resizable
- kODFalse, // Is floating
- kODFalse, // don't save
- kODFalse, // should dispose
- fPartWrapper,
- fFrameView,
- fSynchronizePresentation,
- kODNULL);
-
- if (synchDialog
- && (fArbitrator->RequestFocus(ev, fModalFocus,
- synchWindow->GetRootFrame(ev))))
-
- {
- fMenuBar->DisableAll(ev);
- fMenuBar->EnableCommand(ev, kODCommandEditMenu, kODTrue ) ;
- InvalMenuBar();
-
- SetCursor(&ODQDGlobals.arrow);
- synchWindow->Open(ev);
- synchWindow->Show(ev);
- synchWindow->Select(ev);
- ODReleaseObject(ev, synchWindow);
-
- }
- }
-
-
- void ClockPart::NewFloater(Environment* ev, ODFrame* frame)
- {
- ODSLong savedRefNum;
-
- BeginUsingLibraryResources(savedRefNum);
- DialogPtr dialog = GetNewDialog(kClock_FloatingDialogID ,0,(WindowPtr)-1L);
- EndUsingLibraryResources(savedRefNum);
-
- ODWindow* window = fSOMSelf->GetStorageUnit(ev)->GetSession(ev)->GetWindowState(ev)->
- RegisterWindow(ev, dialog,
- kODNonPersistentFrameObject,
- kODFalse, // Keeps draft open
- kODFalse, // Is resizable
- kODTrue, // Is floating
- kODFalse, // don't save
- kODTrue, // should dispose
- fPartWrapper,
- fFrameView,
- fDialogPresentation,
- kODNULL);
-
-
- if (dialog && window)
- {
- window->Open(ev);
- window->Show(ev);
- window->Select(ev);
- }
-
- ODReleaseObject(ev, window);
- }
-
- void ClockPart::NewSinker(Environment* ev, ODFrame* frame)
- {
- ODSLong savedRefNum;
-
- BeginUsingLibraryResources(savedRefNum);
- DialogPtr dialog = GetNewDialog(kClock_SinkingDialogID ,0,(WindowPtr)-1L);
- EndUsingLibraryResources(savedRefNum);
-
- ODWindow* window = fSOMSelf->GetStorageUnit(ev)->GetSession(ev)->GetWindowState(ev)->
- RegisterWindow(ev, dialog,
- kODNonPersistentFrameObject,
- kODFalse, // Keeps draft open
- kODFalse, // Is resizable
- kODFalse, // Is floating
- kODFalse, // don't save
- kODTrue, // should dispose
- fPartWrapper,
- fFrameView,
- fDialogPresentation,
- kODNULL);
-
-
- if (dialog && window)
- {
- window->Open(ev);
- window->Show(ev);
- window->Select(ev);
- }
-
- ODReleaseObject(ev, window);
- }
-
- void ClockPart::HandleSizeMenu(Environment *ev, ODUShort item, ODFrame* frame)
- {
- AEDesc obj, size;
- ODError err = noErr;
- ODSShort fontSize = 0;
-
- switch (item)
- {
- case kClock_Size_9Pt: fontSize = 9; break;
- case kClock_Size_10Pt: fontSize = 10; break;
- case kClock_Size_11Pt: fontSize = 11; break;
- case kClock_Size_12Pt: fontSize = 12; break;
- case kClock_Size_14Pt: fontSize = 14; break;
- case kClock_Size_18Pt: fontSize = 18; break;
- case kClock_Size_24Pt: fontSize = 24; break;
- case kClock_Size_36Pt: fontSize = 36; break;
- default:
- fontSize = 12;
- }
- THROW_IF_ERROR( AECreateDesc(typeShortInteger, &fontSize, sizeof(fontSize), &size) );
- this->CreatePropObjSpec(ev, pPointSize, obj);
- TRY
- this->SendSetDataEvent(ev, obj, size, frame);
- CATCH_ALL
- err = ErrorCode();
- ENDTRY
- AEDisposeDesc(&size);
- AEDisposeDesc(&obj);
- THROW_IF_ERROR(err);
- }
-
- void ClockPart::HandleStyleMenu(Environment *ev, ODUShort item, ODFrame* frame)
- {
- AEDesc obj, style;
- DescType fontStyle;
- ODError err = noErr;
-
- switch (item)
- {
- case kClock_Style_Plain: fontStyle = kAEPlain; break;
- case kClock_Style_Bold: fontStyle = kAEBold; break;
- case kClock_Style_Italic: fontStyle = kAEItalic; break;
- case kClock_Style_Underline: fontStyle = kAEUnderline; break;
- case kClock_Style_Outline: fontStyle = kAEOutline; break;
- case kClock_Style_Shadow: fontStyle = kAEShadow; break;
- case kClock_Style_Condense: fontStyle = kAECondensed; break;
- case kClock_Style_Extend: fontStyle = kAEExpanded; break;
- default:
- fontStyle = kAEPlain;
- }
-
- THROW_IF_ERROR( AECreateDesc(typeEnumerated, &fontStyle, sizeof(fontStyle), &style) );
- this->CreatePropObjSpec(ev, pTextStyles, obj);
- TRY
- this->SendSetDataEvent(ev, obj, style, frame);
- CATCH_ALL
- err = ErrorCode();
- ENDTRY
- AEDisposeDesc(&style);
- AEDisposeDesc(&obj);
- THROW_IF_ERROR(err);
- }
-
- void ClockPart::SendClockModeEvent(Environment *ev, ODBoolean analog, ODFrame* frame)
- {
- AEDesc obj, mode;
- DescType clockMode;
- ODError err = noErr;
-
- clockMode = kAEDigitalClock;
- if (analog)
- clockMode = kAEAnalogClock;
- THROW_IF_ERROR( AECreateDesc(typeEnumerated, &clockMode, sizeof(clockMode), &mode) );
- this->CreatePropObjSpec(ev, pDisplayMode, obj);
- TRY
- this->SendSetDataEvent(ev, obj, mode, frame);
- CATCH_ALL
- err = ErrorCode();
- ENDTRY
- AEDisposeDesc(&mode);
- AEDisposeDesc(&obj);
- THROW_IF_ERROR(err);
- }
-
-
- ODFrame* ClockPart::GetFirstFrame()
- {
- WASSERT(fContentFrames != kODNULL);
- ODFrame* frame = (ODFrame*) fContentFrames->First();
- WASSERT(frame != kODNULL);
- return frame;
- }
-
- void ClockPart::SetAnalog(Environment* ev, ODBoolean analog)
- {
- if (fAnalog != analog)
- {
- fAnalog = analog;
- fDirty = kODTrue;
- fSOMSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
- }
- }
-
- void ClockPart::SetFont(Environment *ev, ODSShort fontNum)
- {
- if (fFont != fontNum)
- {
- fFont = fontNum;
- fDirty = kODTrue;
- fSOMSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
- }
- }
-
- void ClockPart::SetFontSize(Environment *ev, ODSShort fontSize)
- {
- if (fSize != fontSize)
- {
- fSize = fontSize;
- fDirty = kODTrue;
- fSOMSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
- }
- }
-
- void ClockPart::SetFontStyle(Environment *ev, ODUByte fontStyle )
- {
- if (fStyle != fontStyle)
- {
- fStyle = fontStyle;
- fDirty = kODTrue;
- fSOMSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
- }
- }
-
- ODWindow* ClockPart::CreateWindow(Environment *ev, WindowProperties& props, ODFrame* rootFrame)
- {
- ODWindow* window = kODNULL;
- ODPlatformWindow platformWindow = this->CreatePlatformWindow(props);
- if (rootFrame)
- {
- window = fSession->GetWindowState(ev)->RegisterWindowForFrame(ev,
- platformWindow,
- rootFrame,
- props.isRootWindow, // Keeps draft open
- props.isResizable, // Is resizable
- props.isFloating, // Is floating
- (props.sourceFrame == kODNULL), // shouldSave
- kODFalse, // should dispose
- props.sourceFrame);
- }
- else
- {
- window = fWindowState->
- RegisterWindow(ev, platformWindow,
- kODFrameObject,
- props.isRootWindow, // is root
- props.isResizable, // Is resizable
- props.isFloating, // Is floating
- (props.sourceFrame == kODNULL), // should save
- kODFalse, // should dispose
- fPartWrapper,
- fFrameView,
- fTimePresentation,
- props.sourceFrame);
- }
- return window;
- }
-
- ODBoolean ClockPart::HandleOSEvent(Environment* ev, ODEventData* event, ODFrame* frame, ODFacet* facet)
- {
- const short kSuspendResumeMessage = 0x01; // Resume vs. suspend mask
- unsigned char typeOSEvent;
-
- // • Is it a multifinder event?
- typeOSEvent = (unsigned char) (event->message >> 24) & 0x00FF;
-
- // • Switch on the type of OSEvent that occurred, high byte of message is event type
- switch (typeOSEvent)
- {
- case kSuspendResumeMessage:
- {
- ClockFrame* clockFrame = (ClockFrame*) frame->GetPartInfo(ev);
- const short kResumeMask = 0x01; // High byte suspend/resume event
- ODBoolean goingToBackground = (event->message & kResumeMask) == 0;
-
- if (goingToBackground)
- {
- #if defined(ODDebug) && ODDebugLayers
- somPrintf("Clock Going to Background. Frame: %x Facet: %x\n", frame, facet);
- #endif
- clockFrame->SuspendProcess(ev);
- }
- else
- {
- #if defined(ODDebug) && ODDebugLayers
- somPrintf("Clock Coming to Foreground. Frame: %x Facet: %x\n", frame, facet);
- #endif
- clockFrame->ResumeProcess(ev);
-
- }
- }
- default:
- break;
- }
- return kODTrue;
- }
-
- ODID ClockPart::OpenInitialWindow(Environment *ev)
- {
- ODWindow* window = kODNULL;
- WindowProperties props;
- this->GetDefaultWindowProperties(ev, &props, kODNULL);
-
- window = this->CreateWindow(ev, props, kODNULL);
- ODID windowID = window->GetID(ev);
- window->Open(ev);
- window->Show(ev);
- window->Select(ev);
- ODReleaseObject(ev, window);
- return windowID;
- }
-
- void ClockPart::GetDefaultWindowProperties(Environment* ev, WindowProperties* props, ODFrame* sourceFrame)
- {
- CopyPascalString(props->title, "\pClock");
- props->procID = zoomDocProc;
- props->hasCloseBox = kODTrue;
- props->refCon = 0;
- props->wasVisible = kODTrue;
- props->isResizable = kODTrue;
- props->isFloating = kODFalse;
- props->isRootWindow = (sourceFrame == kODNULL);
- props->shouldShowLinks = kODFalse;
- props->sourceFrame = sourceFrame;
-
- this->CalcClockBounds(props->boundsRect);
- if (!fAnalog)
- {
- props->boundsRect.right += 15;
- props->boundsRect.bottom += 15;
- }
- OffsetRect(&props->boundsRect, 40, 40);
-
- ODName* windowName = kODNULL;
- if (sourceFrame)
- windowName = ODGetPartName(ev, sourceFrame, kODNULL);
- if (windowName==kODNULL || GetITextStringLength(windowName)==0)
- CopyPascalString(props->title, "\pClock");
- else
- GetITextPString(windowName, props->title);
- if (windowName)
- DisposeIText(windowName);
- }
-
- ODPlatformWindow ClockPart::CreatePlatformWindow(WindowProperties& props)
- {
- ODPlatformWindow platformWindow = NewCWindow((Ptr)ODNewPtr(sizeof(WindowRecord)),
- &(props.boundsRect),
- props.title,
- kODFalse /*visible */,
- props.procID,
- (WindowPtr)-1L,
- props.hasCloseBox,
- props.refCon);
- return platformWindow;
- }
-
- ODID ClockPart::OpenRootFrame(Environment *ev, ODFrame* frame)
- {
- ODWindow* window = kODNULL;
- ODID windowID = 0;
- WindowProperties props;
-
- ODBoolean hasWindowProperties = BeginGetWindowProperties(ev, frame, &props);
- if (!hasWindowProperties)
- this->GetDefaultWindowProperties(ev, &props, kODNULL);
- ODPlatformWindow platformWindow = this->CreatePlatformWindow(props);
- ClockFrame* clockFrame = (ClockFrame*) frame->GetPartInfo(ev);
- // Set the platform window early, so that if RegisterWindow fails, clockFrame
- // can still get to the platform window to dispose of it.
- if (clockFrame)
- clockFrame->SetPlatformWindow(platformWindow);
- TRY{
- window = fSession->GetWindowState(ev)->RegisterWindowForFrame(ev, platformWindow,
- frame,
- props.isRootWindow, // Keeps draft open
- kODTrue, // Is resizable
- kODFalse, // Is floating
- kODTrue, // shouldSave
- kODFalse, // should dispose
- props.sourceFrame);
- }CATCH_ALL{
- TRY{
- EndGetWindowProperties(ev, &props); // Release source frame
- }CATCH_ALL{
- //ignore errors
- }ENDTRY
- RERAISE;
- }ENDTRY
- EndGetWindowProperties(ev, &props); // Release source frame
- window->Open(ev);
- window->Show(ev);
- windowID = window->GetID(ev);
- ODReleaseObject(ev, window);
- return windowID;
- }
-
-
- void ClockPart::AdjustMenus(Environment *ev)
- {
- //fMenuBar->EnableCommand(ev, kODCommandViewAsWin, !frame->IsRoot(ev));
- fMenuBar->EnableAndCheckCommand(ev, cAnalog , kODTrue, fAnalog);
- fMenuBar->EnableAndCheckCommand(ev, cDigital , kODTrue, !fAnalog);
-
- Str255 fontName;
- ODPlatformMenu fontMenu = fMenuBar->GetMenu(ev,kClock_FontMenuID);
- GetFontName(fFont, fontName );
- CheckMarkMenu(fontMenu, fontName, kODTrue );
-
- ODIText* menuItem;
- // DON'T DO THIS! FOR LOCALISABILITY, READ THE TEXT OUT OF A RESOURCE AND
- // USE THE CURRENT SYSTEM SCRIPT AND CURRENT SYSTEM LANGUAGE.
- menuItem = CreateIText(smRoman, langEnglish, "About Clock…");
- fMenuBar->SetItemString(ev, kODCommandAbout, menuItem);
- DisposeIText(menuItem);
-
- }
-
- //------------------------------------------------------------------------------
- // ClockPart: HandleMenuEvent
- //------------------------------------------------------------------------------
-
-
- ODBoolean ClockPart::HandleMenuEvent(Environment *ev, ODEventData* event, ODFrame* frame)
- {
- ODBoolean wasHandled = kODTrue;
-
- long menuResult = event->message;
- short menu = HiWord(menuResult);
- short item = LoWord(menuResult);
- ODCommandID command = fMenuBar->GetCommand(ev, menu, item);
-
- if (fMenuBar->IsCommandSynthetic(ev, command)) // Font, Size, Style
- {
- switch ( menu )
- {
- case kClock_FontMenuID:
- this->HandleFontMenu(ev, item, frame );
- break;
- case kClock_SizeMenuID:
- this->HandleSizeMenu(ev, item, frame );
- break;
- case kClock_StyleMenuID:
- this->HandleStyleMenu(ev, item, frame );
- break;
- default:
- wasHandled = kODFalse;
- break;
- }
-
- }
- else
- {
- switch (command)
- {
- case kODCommandAbout:
- this->ShowAboutBox(ev, frame);
- break;
- case cAnalog:
- this->SendClockModeEvent(ev, kODTrue, frame);
- break;
- case cDigital:
- this->SendClockModeEvent(ev, kODFalse, frame);
- break;
- case cSynchronize:
- this->ShowSynchDialog(ev);
- break;
- case cShowAlarmSettings:
- gClockGlobals->OpenAlarmSettingsDialog(ev, frame);
- break;
- case cShowDisplaySettings:
- gClockGlobals->OpenDisplaySettingsDialog(ev, frame);
- this->AdjustDialogs(ev);
- break;
- case cNewFloater:
- this->NewFloater(ev, frame);
- break;
- case cNewSinker:
- this->NewSinker(ev, frame);
- break;
- case cNewMenu:
- {
- if (fExtraMenu == kODNULL)
- {
- fExtraMenu = NewMenu(kClock_ExtraMenuID, "\pMenu");
- AppendMenu(fExtraMenu, "\pDelete Me");
- fMenuBar->AddMenuBefore(ev, kClock_ExtraMenuID, fExtraMenu, fPartWrapper, kClock_FontMenuID);
- fMenuBar->RegisterCommand(ev, cDeleteMenu, kClock_ExtraMenuID, 1);
- }
- else if (fExtraSubMenu == kODNULL)
- {
- fExtraSubMenu = NewMenu(kClock_ExtraSubMenuID, "\pSubMenu");
- AppendMenu(fExtraSubMenu, "\pSubItem");
- AppendMenu(fExtraMenu, "\pHier");
- fMenuBar->AddSubMenu(ev, kClock_ExtraSubMenuID, fExtraSubMenu, fPartWrapper);
- SetItemCmd(fExtraMenu,2, hMenuCmd);
- SetItemMark(fExtraMenu,2, kClock_ExtraSubMenuID);
- }
- else
- SysBeep(2);
-
- }
- break;
- case cDeleteMenu:
- {
- fMenuBar->UnregisterCommand(ev, cDeleteMenu);
- fMenuBar->RemoveMenu(ev, kClock_ExtraMenuID);
- fMenuBar->RemoveMenu(ev, kClock_ExtraSubMenuID);
- if (fExtraMenu)
- {
- DisposeMenu(fExtraMenu);
- fExtraMenu = kODNULL;
- }
- if (fExtraSubMenu)
- {
- DisposeMenu(fExtraSubMenu);
- fExtraSubMenu = kODNULL;
- }
-
- }
- break;
- default:
- wasHandled = kODFalse;
- break;
- }
- }
- return wasHandled;
- }
-
- ODBoolean ClockPart::CloseWindow(Environment* ev, ODFrame* frame)
- {
- ODBoolean handled = kODFalse;
- ODTypeToken presentation = frame->GetPresentation(ev);
-
- if (presentation == fDisplaySettingsPresentation)
- {
- gClockGlobals->CloseDisplaySettingsWindow(ev);
- handled = kODTrue;
- }
- else if (presentation == fAlarmSettingsPresentation)
- {
- gClockGlobals->CloseAlarmSettingsWindow(ev);
- handled = kODTrue;
- }
-
- return handled;
- }
-
-
- ODShape* ClockPart::CreateOvalShape(Environment* ev, ODFrame* frame, Rect& rect)
- {
- GrafPtr savedPort;
- GetPort(&savedPort);
- SetPort(fWorkPort);
- RgnHandle region = ODNewRgn();
- OpenRgn();
- FrameOval(&rect);
- CloseRgn(region);
-
- ODShape* newShape = frame->CreateShape(ev);
- newShape->SetQDRegion(ev, region);
- SetPort(savedPort);
- return newShape;
- }
-
-
- ClockSI* ClockPart::AquireSI(Environment* ev)
- {
- fSemanticInterface->Acquire(ev);
- return fSemanticInterface;
- }
-
-
- #ifndef ff
- #define ff(N) ( (ODCoordinate)(N) <<16 ) // Converts integer to fixed (ODCoordinate)
- #endif
-
- void ClockPart::CalcClockBounds(Rect& rect)
- {
- if (fAnalog)
- SetRect(&rect, 0,0,150,150);
- else
- {
- GrafPtr savedPort;
- GetPort(&savedPort);
- SetPort(fWorkPort);
-
- TextFont(fFont);
- TextFace(fStyle );
- TextMode(srcCopy );
- TextSize(fSize );
-
- FontInfo fontIRec;
- GetFontInfo( &fontIRec );
- fLastAscent = fontIRec.ascent;
-
- // • • move to resource for localization
- //rect.Set(0, 0, ff(StringWidth("\p12:59:59 MM")+4),
- // ff((fontIRec.ascent+fontIRec.descent+fontIRec.leading)+2) );
- SetRect(&rect, 0, 0, StringWidth("\p12:59:59 MM")+4,
- (fontIRec.ascent+fontIRec.descent+fontIRec.leading)+2 );
- SetPort(savedPort);
- }
- } // ClockPart::CalcClockBounds
-
-
- void ClockPart::CreatePropObjSpec(Environment* ev, DescType prop, AEDesc& objSpec)
- {
- AEDesc nullDesc = NULL_DESCRIPTOR_DEFINITION;
- AEDesc pr = NULL_DESCRIPTOR_DEFINITION;
- DescType activePart;
-
- // create "prop of active part" reference
- activePart = pActivePart;
- TRY
- // active part
- THROW_IF_ERROR( AECreateDesc(typeType, (Ptr) &activePart, sizeof(activePart), &pr) );
- THROW_IF_ERROR( CreateObjSpecifier(cProperty, &nullDesc, formPropertyID, &pr, kODTrue, &objSpec) );
- // prop of active part
- THROW_IF_ERROR( AECreateDesc(typeType, (Ptr) &prop, sizeof(prop), &pr) );
- THROW_IF_ERROR( CreateObjSpecifier(cProperty, &objSpec, formPropertyID, &pr, kODTrue, &objSpec) );
- CATCH_ALL
- AEDisposeDesc(&pr);
- RERAISE;
- ENDTRY
- } // ClockPart::CreatePropObjSpec
-
-
- void ClockPart::SendSetDataEvent(Environment* ev, AEDesc& objSpec, AEDesc& data, ODFrame* frame)
- {
- ODAddressDesc* address = kODNULL;
- ODAppleEvent* event = kODNULL;
- ODAppleEvent* reply = kODNULL;
- AEDesc aeevent = NULL_DESCRIPTOR_DEFINITION;
- ODMessageInterface* mess = kODNULL;
- ODError err = noErr;
- TempODFrame activeFrame = AquirePersistantFrame(ev, frame);
- TempODPart part = activeFrame->AcquirePart(ev);
- AEDesc nullDesc = NULL_DESCRIPTOR_DEFINITION;
- AEDesc subject = NULL_DESCRIPTOR_DEFINITION;
- AEDesc pr = NULL_DESCRIPTOR_DEFINITION;
- DescType activePart;
-
- ODVolatile(address);
- ODVolatile(event);
- ODVolatile(reply);
-
- TRY
- // get the message interface
- mess = fSOMSelf->GetStorageUnit(ev)->GetSession(ev)->GetMessageInterface(ev);
- // create an event
- mess->CreatePartAddrDesc(ev, &address, fSOMSelf);
- mess->CreateEvent(ev, kAECoreSuite, kAESetData, address, kAnyTransactionID, &event);
- ODDescToAEDesc(event, &aeevent);
- // add direct parameter and data parameter
- THROW_IF_ERROR( AEPutParamDesc(&aeevent, keyDirectObject, &objSpec) );
- THROW_IF_ERROR( AEPutParamDesc(&aeevent, keyAEData, &data) );
- // add the active part subject attribute
- activePart = pActivePart;
- THROW_IF_ERROR( AECreateDesc(typeType, (Ptr) &activePart, sizeof(activePart), &pr) );
- THROW_IF_ERROR( CreateObjSpecifier(cProperty, &nullDesc, formPropertyID, &pr, kODTrue, &subject) );
- THROW_IF_ERROR( AEPutAttributeDesc(&aeevent, keySubjectAttr, &subject) );
- AEDescToODDesc(&aeevent, event);
- // create the reply
- reply = new ODAppleEvent;
- THROW_IF_NULL(reply);
- reply->InitODAppleEvent(ev);
- // send the event with a null frame so no part id subject is added (which would stomp ours)
- mess->Send(ev, kODNULL, part, event, reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout);
- CATCH_ALL
- err = ErrorCode();
- ENDTRY
- AEDisposeDesc(&aeevent);
- AEDisposeDesc(&subject);
- // AEDisposeDesc(&pr); // this one should already be disposed by CreateObjectSpecifier
- ODDeleteObject(address);
- ODDeleteObject(event);
- ODDeleteObject(reply);
- THROW_IF_ERROR(err);
- }
-
- ODFrame* AquirePersistantFrame(Environment* ev, ODFrame* frame)
- {
- // Temporary hack to use activeFrame, otherwise we fail when a dialog is up,
- // because its frame is nonpersistent
- // A better approach might be to add delegation of menu commands from
- // dialog frames to the source frame of the dialog window.
- //TempODFrame activeFrame = fArbitrator->AcquireFocusOwner(ev, fSession->Tokenize(ev, kODSelectionFocus));
-
- ODFrame* activeFrame = kODNULL;
- if (frame->GetStorageUnit(ev) == kODNULL)
- {
- TempODWindow window = frame->AcquireWindow(ev);
- activeFrame = window->AcquireSourceFrame(ev);
- }
- else
- {
- activeFrame = frame;
- activeFrame->Acquire(ev);
- }
- return activeFrame;
- }
-
-